import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export default defineEventHandler(async (event) => {
  if (event.context.userId == null) {
    return responseJson(1, "未登录", null);
  }
  try {
    const userInfo = await prisma.user.findUniqueOrThrow({
      select: {
        id: true,
        name: true,
        username: true,
        phone: false,
      },
      where: {
        id: event.context.userId,
      },
    });
    return responseJson(0, "ok", userInfo);
  } catch (e) {
    return responseJson(400, "error", e);
  }
});
